import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;


public class Dbutil {
	Connection con = null; // 建立数据库连接对象
	PreparedStatement pst = null; // 使用Statment类声明一个Sql语句对象
	ResultSet rs = null; // 声明结果集对象，用于存放查询结果
	String dbClass = "";
	String dbUrl = "";
	String dbPort = "";
	String databaseName = "";
	String dbUserName = "";
	String dbPassword = "";
	String dbAreacode="";
	int start=0;
	int end=0;
	String fileName="";
	public  String getProp(String key) {
		Properties props = new Properties();
		InputStream in = getClass().getResourceAsStream(
				"/"+fileName);
		try {
			props.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String value = props.getProperty(key);
		return value;
	}
	public void load(String dbNmae){
		if(dbNmae=="picc"){
			this.fileName="picc.properties";
		}else if(dbNmae=="wxpiccdx3g"){
			this.fileName="wxpiccdx3g.properties";
		}
		dbClass = getProp("dbClass");
		dbUrl = getProp("dbUrl");
		dbPort = getProp("dbPort");
		databaseName = getProp("databaseName");
		dbUserName = getProp("dbUserName");
		dbPassword = getProp("dbPassword");
		dbAreacode=getProp("Areacode");
		start=Integer.parseInt(getProp("start"));
		end=Integer.parseInt(getProp("end"));
	}
	public Connection getConnection(){
		
		try {
			Class.forName(dbClass);
			con = DriverManager.getConnection("jdbc:oracle:thin:@"+dbUrl+":"+dbPort+":"+databaseName+"", ""+dbUserName+"", ""+dbPassword+""); // 与指定数据库建立连接
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	public void close(){
		if(con==null){
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public int getStart() {
		return start;
	}
	public int getEnd() {
		return end;
	}
	public String getDbAreacode() {
		return dbAreacode;
	}

}
